package com.example.thornchg.yc_plane_game;

import org.cocos2d.actions.base.CCRepeatForever;
import org.cocos2d.actions.instant.CCCallFunc;
import org.cocos2d.actions.interval.CCMoveBy;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.types.CGSize;

public class CombatMap {
    private CCSprite ccSprite_map_2;
    private CGSize winSize;
    private CCSprite ccSprite_map_1;

    public CombatMap(CCLayer ccLayer) {
        winSize = CCDirector.sharedDirector().getWinSize();
        ccSprite_map_1 = CCSprite.sprite("background.png");
        ccSprite_map_1.setScaleX(winSize.getWidth() / ccSprite_map_1.getContentSize().width);
        ccSprite_map_1.setScaleY(winSize.getWidth() / ccSprite_map_1.getContentSize().width);
        ccSprite_map_1.setAnchorPoint(0, 0);
        ccLayer.addChild(ccSprite_map_1);
        CCMoveBy ccMoveBy1 = CCMoveBy.action(.8f, CCLayer.ccp(0, -50));
        CCCallFunc ccCallFunc1 = CCCallFunc.action(this, "moveByEnd");
        CCSequence ccSequence1 = CCSequence.actions(ccMoveBy1, ccCallFunc1);
        CCRepeatForever ccRepeatForever1 = CCRepeatForever.action(ccSequence1);
        ccSprite_map_1.runAction(ccRepeatForever1);
        ccSprite_map_2 = CCSprite.sprite("background.png");
        ccSprite_map_2.setScaleX(winSize.getWidth() / ccSprite_map_2.getContentSize().width);
        ccSprite_map_2.setScaleY(winSize.getWidth() / ccSprite_map_2.getContentSize().width);
        ccSprite_map_2.setAnchorPoint(0, 0);
        ccSprite_map_2.setPosition(0, ccSprite_map_2.getBoundingBox().size.getHeight());
        ccLayer.addChild(ccSprite_map_2);
        CCMoveBy ccMoveBy2 = CCMoveBy.action(.8f, CCLayer.ccp(0, -50));
        CCCallFunc ccCallFunc2 = CCCallFunc.action(this, "moveByEnd");
        CCSequence ccSequence2 = CCSequence.actions(ccMoveBy2, ccCallFunc2);
        CCRepeatForever ccRepeatForever2 = CCRepeatForever.action(ccSequence2);
        ccSprite_map_2.runAction(ccRepeatForever2);

    }
    public void moveByEnd() {
        if (ccSprite_map_1.getPosition().y < -ccSprite_map_1.getBoundingBox().size.getHeight()) {
            ccSprite_map_1.setPosition(CCLayer.ccp(0,
                    ccSprite_map_1.getBoundingBox().size.getHeight() - 50));
        } else if (ccSprite_map_2.getPosition().y < -ccSprite_map_2.getBoundingBox().size.getHeight()) {
            ccSprite_map_2.setPosition(CCLayer.ccp(0,
                    ccSprite_map_2.getBoundingBox().size.getHeight() - 50));
        }
    }
}
